home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 8
/
Eagles_Nest_Mac_Collection_Disc_8.TOAST
/
Developer Tools⁄Additions
/
InsideBa1994
/
InsideBasic-94
/
IB 94
/
TextFileReader
/
Text File Reader.BAS
Wrap
BASIC Source File
|
1993-05-05
|
1KB
|
34 lines
LOCAL FN ReadTextFile (efID)
DIM rect.8
fileName$ = FILES$ (_fOpen, "TEXT", , vRefNum%)
LONG IF fileName$ <> ""
OPEN "I", #1, fileName$, , vRefNum%'open file here
LONG IF SYSERROR = _noErr 'whew, no error
size% = LOF (1,1) 'get file size
LONG IF size% < 32767 'will all text fit?
hndl& = FN NEWHANDLE (size% + 2)'create handle of size
LONG IF hndl& <> 0 AND SYSERROR = _noErr'got valid handle?
osErr = FN HLOCK(hndl&) 'lock in memory
POKE WORD [hndl&], size% 'poke length into handle
READ FILE #1, [hndl&] + 2, size%'read text file to handle
osErr = FN HUNLOCK (hndl&)'unlock text handle
EDIT FIELD #efID, &hndl& 'put text into edit field
DEF DISPOSEH (hndl&) 'release memory
XELSE
BEEP : BEEP 'can’t get handle error
END IF
XELSE
BEEP : BEEP 'text file too large!!
END IF
CLOSE #1 'close text file
XELSE
BEEP : BEEP 'file open error
END IF
END IF
END FN